/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.MailConstants;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Map;
/*     */ import java.util.concurrent.ConcurrentHashMap;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.eclipse.jetty.continuation.Continuation;
/*     */ import org.eclipse.jetty.continuation.ContinuationSupport;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class NoOp
/*     */   extends MailDocumentHandler
/*     */ {
/*  55 */   private static final long DEFAULT_TIMEOUT = LC.zimbra_noop_default_timeout.longValue() * 1000L;
/*  56 */   private static final long MIN_TIMEOUT = LC.zimbra_noop_min_timeout.longValue() * 1000L;
/*  57 */   private static final long MAX_TIMEOUT = LC.zimbra_noop_max_timeout.longValue() * 1000L;
/*     */   
/*     */   private static long parseTimeout(Element request) throws ServiceException
/*     */   {
/*  61 */     long timeout = request.getAttributeLong("timeout", DEFAULT_TIMEOUT);
/*  62 */     if (timeout < MIN_TIMEOUT)
/*  63 */       timeout = MIN_TIMEOUT;
/*  64 */     if (timeout > MAX_TIMEOUT)
/*  65 */       timeout = MAX_TIMEOUT;
/*  66 */     return timeout;
/*     */   }
/*     */   
/*     */   public void preProxy(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  71 */     setProxyTimeout(parseTimeout(request) + 10000L);
/*  72 */     super.preProxy(request, context);
/*     */   }
/*     */   
/*  75 */   ConcurrentHashMap<String, ZimbraSoapContext> sBlockedNops = new ConcurrentHashMap(5000, 0.75F, 50);
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  80 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  81 */     boolean wait = request.getAttributeBool("wait", false);
/*  82 */     boolean includeDelegates = request.getAttributeBool("delegate", true);
/*  83 */     HttpServletRequest servletRequest = (HttpServletRequest)context.get("servlet.request");
/*     */     
/*  85 */     boolean enforceLimit = request.getAttributeBool("limitToOneBlocked", false);
/*  86 */     boolean blockingUnsupported = false;
/*     */     
/*     */ 
/*     */ 
/*  90 */     if (zsc.hasCreatedSession()) {
/*  91 */       wait = false;
/*     */     }
/*  93 */     if (wait) {
/*  94 */       if (!zsc.hasSession()) {
/*  95 */         throw ServiceException.INVALID_REQUEST("Cannot execute a NoOpRequest with wait=\"1\" without a session.  Set the <session> flag in the <context> of your request", null);
/*     */       }
/*     */       
/*  98 */       ZimbraSoapContext origContext = (ZimbraSoapContext)servletRequest.getAttribute("nop_origcontext");
/*  99 */       if (origContext == null) {
/* 100 */         servletRequest.setAttribute("nop_origcontext", zsc);
/*     */         
/* 102 */         Continuation continuation = ContinuationSupport.getContinuation(servletRequest);
/* 103 */         if (zsc.beginWaitForNotifications(continuation, includeDelegates)) {
/* 104 */           if (enforceLimit) {
/* 105 */             ZimbraSoapContext otherContext = (ZimbraSoapContext)this.sBlockedNops.put(zsc.getAuthtokenAccountId(), zsc);
/* 106 */             if (otherContext != null) {
/* 107 */               otherContext.signalNotification(true);
/*     */             }
/*     */           }
/*     */           
/* 111 */           synchronized (zsc) {
/* 112 */             if (zsc.waitingForNotifications())
/*     */             {
/* 114 */               long timeout = parseTimeout(request);
/* 115 */               if (ZimbraLog.soap.isTraceEnabled())
/* 116 */                 ZimbraLog.soap.trace("Suspending <NoOpRequest> for %dms", new Object[] { Long.valueOf(timeout) });
/* 117 */               zsc.suspendAndUndispatch(timeout);
/*     */             }
/*     */             
/*     */ 
/*     */ 
/* 122 */             if (zsc.isCanceledWaitForNotifications())
/* 123 */               blockingUnsupported = true;
/*     */           }
/*     */         }
/* 126 */         if (enforceLimit)
/*     */         {
/*     */ 
/* 129 */           this.sBlockedNops.remove(zsc.getAuthtokenAccountId(), zsc);
/*     */         }
/*     */       } else {
/* 132 */         if (origContext.isCanceledWaitForNotifications())
/* 133 */           blockingUnsupported = true;
/* 134 */         if (enforceLimit)
/*     */         {
/*     */ 
/* 137 */           this.sBlockedNops.remove(origContext.getAuthtokenAccountId(), origContext);
/*     */         }
/*     */       }
/*     */     }
/* 141 */     Element toRet = zsc.createElement(MailConstants.NO_OP_RESPONSE);
/* 142 */     if (blockingUnsupported) {
/* 143 */       toRet.addAttribute("waitDisallowed", true);
/*     */     }
/*     */     
/* 146 */     return toRet;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/NoOp.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */